<template>
  <a-radio-group :default-value="null" button-style="solid" v-model="stateValue" @change="$emit('change', $event.target.value)">
    <a-radio-button :value="null">
      全部
    </a-radio-button>
    <a-radio-button @change="change" :value="id" v-for="{id, name} in filteredOrgList">
      {{ name }}
    </a-radio-button>
  </a-radio-group>
</template>
<script>
import {list as emsOrgList} from '@/api/modular/main/emsorg/emsOrgManage'

export default {
  name: 'FCOrgRadioGroup',
  model: {
    prop: 'orgId',
    event: 'change'
  },
  props: {
    orgId: 0,
    filterTypes: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      stateValue: null,
      sysOrgs: []
    }
  },
  computed: {
    filteredOrgList() {
      let _this = this
      let orgList = this.$util.getOrgList(this.filterTypes)
      return orgList
    },
  },
  watch: {
    orgId(newValue) {
      this.stateValue = newValue
    }
  },
  methods: {
    change(){
      this.$emit('change')
    },
    getOrgList() {
      if (this.$util.ORG_LIST) {
        this.sysOrgs = this.$util.ORG_LIST
      } else {
        emsOrgList().then((res) => {
          this.$util.ORG_LIST = res.data
          this.sysOrgs = res.data
        })
      }
    }
  },
  created() {
    // this.getOrgList()
  }
}
</script>
<style lang="less">

button {
  margin-right: 8px;
}

</style>